import { of,Observable, interval, take,retry } from "rxjs";
import { map, filter,reduce,find,findIndex } from 'rxjs/operators'


//类似于迭代器 next 发出通知  complete通知完成
const observable = new Observable(subscriber=>{
  subscriber.next(1)
  subscriber.next(2)
  subscriber.next(3)

  setTimeout(()=>{
      subscriber.next(4)
      subscriber.complete()
  },1000)
})

observable.subscribe({
  next:(value)=>{
     console.log(value)
  }
})

const subs = interval(500).pipe(map(v => ({ num: v })), filter(v => (v.num % 2 == 0))).subscribe((e) => {
    console.log(e)
    if (e.num == 10) {
        subs.unsubscribe()
    }
})


const subs2 = of(1,2,3,4,5,6).pipe(retry(3),map(v => ({ num: v })), filter(v => (v.num % 2 == 0))).subscribe((e) => {
  console.log(e)
  if (e.num == 10) {
      subs2.unsubscribe()
  }
})

